<?php

	require_once("Client.php");

	class AddClientController{

		var $company;
		var $address;
		var $cellNo;
		var $telNo;
		var $faxNo;
		var $emailAdd;
		
		var $flag;
		var $client;

		function sendData(){
			$this->client = $_REQUEST['client'];
			$this->company = $_REQUEST['company'];
			$this->address = $_REQUEST['address'];
			$this->cellNo = $_REQUEST['cellNo'];
			$this->telNo = $_REQUEST['telNo'];
			$this->faxNo = $_REQUEST['faxNo'];
			$this->emailAdd = $_REQUEST['emailAdd'];
			$this->flag = $_REQUEST['flag'];
			$this->sort = $_REQUEST['sort'];
		}
		
				
		function retrieveClients(){
			$client = new Client;
			$client->retrieve();
		}

	}
		
	$addClientController = new AddClientController;
	$addClientController->sendData();
	
	if($addClientController->flag=="retrieveAllClients"){
		$addClientController->retrieveClients();
	}	
	elseif($addClientController->flag=="submit"){
			echo "	<script>";

			echo "		company = \"".$addClientController->company."\";";
			echo "		address = \"".$addClientController->address."\";";
			echo "		cellNo = \"".$addClientController->cellNo."\";";
			echo "		telNo = \"".$addClientController->telNo."\";";
			echo "		faxNo = \"".$addClientController->faxNo."\";";
			echo "		emailAdd = \"".$addClientController->emailAdd."\";";
			echo "		flag = \"add\";";
			
			echo "		from = \"confirm\";";
			
			echo "		$.post('viewClientInfo.php',{";		
			echo "			company: company,";
			echo "			address: address,";
			echo "			cellNo: cellNo,";
			echo "			telNo: telNo,";
			echo "			faxNo: faxNo,";
			echo "			emailAdd: emailAdd,";
			echo "			flag: flag,";
			
			echo "			from:from";
			echo "			},function(data){";
			echo "				$('#view').html(data);";
			echo "			}";
			echo "		);";
			echo "	</script>";
	}
	elseif($addClientController->flag=="confirm"){
		$client = new Client();
		$client->sendClientDetails($addClientController->company, $addClientController->company, $addClientController->address, $addClientController->cellNo, $addClientController->telNo, $addClientController->faxNo, $addClientController->emailAdd);
		$client->add();
	}
?>